<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item prop="title">
        <el-input v-model="queryParams.title" placeholder="请输入会议标题" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item prop="deptName">
        <el-input v-model="queryParams.deptName" placeholder="请输入承办部门" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item prop="beginTimeCondition">
        <el-date-picker clearable v-model="queryParams.startTime" type="datetime" value-format="yyyy-MM-dd HH:mm"
          placeholder="请选择开始时间"></el-date-picker>
      </el-form-item>
      <el-form-item prop="endTimeCondition">
        <el-date-picker clearable v-model="queryParams.endTime" type="datetime" value-format="yyyy-MM-dd HH:mm"
          placeholder="请选择结束时间"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-select class="select-width" v-model="queryParams.businessStatus" filterable clearable placeholder="请选择类型">
          <el-option v-for="(item, index) in types" :key="index" :label="item.type" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="linesList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" align="center" />
      <el-table-column label="会议标题" align="center" prop="title" />
      <el-table-column label="承办部门" align="center" prop="deptName" />
      <el-table-column label="承办人" align="center" prop="agentName" />
      <el-table-column label="发起日期" align="center" prop="createTime">
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" width="180">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status=='DONE'" type="success" color="#EFFFEB">{{scope.row.statusName}}</el-tag>
          <el-tag v-else-if="scope.row.status=='DRAFT'" type="warning" color="#FFF1D2">{{scope.row.statusName}}</el-tag>
          <el-tag v-else type="info" color="#F3F3F3">{{scope.row.statusName}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200" fixed="right" align="right">
        <template slot-scope="scope">
          <el-button v-if="['DRAFT'].includes(scope.row.status)" type="danger" size="mini" @click="handleAdd(scope.row)">办理</el-button>
          <el-button type="primary" size="mini" @click="handleDetail(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <my-room-detail v-if="upload.open" :upload="upload" @getList="getList"></my-room-detail>
  </div>
</template>

<script>
import { hyapUpdate } from '../../../api/xzgl/hyyd';
import { auditList, taskList } from '../../../api/xzgl/hytz';
import { getInfo } from '@/api/login'
import myRoomDetail from './myRoomDetail.vue';
export default {
  components: { myRoomDetail },
  data() {
    return {
      // DRAFT(0, "草稿"), UNDO(1, "在办(送审)"), DONE(2, "办结(结束流程)"), AUDIT(6, "审批中"), AUDITED(7, "已审批"), FINISH(8, "已归档(已发送)"), REBACK(9, "已撤回")
      types: [{
        type: '草稿',
        value: 'DRAFT'
      }, {
        type: '在办',
        value: 'UNDO'
      },
      {
        type: '办结',
        value: 'DONE'
      },
      {
        type: '审批中',
        value: 'AUDIT'
      },
      {
        type: '已审批',
        value: 'AUDITED'
      },
      {
        type: '归档',
        value: 'FINISH'
      },
      {
        type: '撤回',
        value: 'REBACK'
      }],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 路线表格数据
      linesList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        flCreatorId: null
      },
      // 表单参数
      form: {},
      linesListAll: [],
      flag: 0,
      upload: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题
        title: "会议安排申请",
        way: '2',
        row: {}
      },
    };
  },
  created() {
    console.log(11,this.$route.query.meetName);
    if (this.$route.query.meetName) {
      this.queryParams.title = this.$route.query.meetName
    }
    this.UserInfo()
    // this.getList();
    // this.getAllLines();
  },
  methods: {
    UserInfo() {
      getInfo().then(res => {
        this.getList()
      })
    },
    /** 查询路线列表 */
    getList() {
      this.loading = true;
      taskList(this.queryParams).then(response => {
        console.log('list', response)
        this.linesList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        // lineType: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        name: '',
        id: null
      }
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {

      this.ids = selection.map(item => item.id)
      // console.log('ids',this.ids);
      // console.log('selection',selection);

      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd(row = null) {
      this.reset();
      if(row) {
        this.upload.row = row
        this.upload.type = '2'
        this.upload.way = '2'
      }else{
        this.upload.type = '1'
        this.upload.way = '0'
      }
      this.upload.open = true
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      let ids = row.id;
      this.$modal.confirm('是否确认办理').then(function () {
        const params = {
          id: ids,
          status: 1
        }
        return hyapUpdate(params);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("办理成功");
      }).catch((e) => {
        console.log('取消办理', e);
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.flag) {
            PupdateLines(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.queryParams.id = null
              this.getList();
            });
          } else {
            PaddLines(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      // this.$router.push({ path: '/xzgl/hyyd/myRoomDetail', query: {id: row.id} })
      this.upload.row = row
      this.upload.type = '0'
      this.upload.way = '2'
      this.upload.title = '详情'
      this.upload.open = true
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('/workflow/taskinfo/export/MEETING', {
        ...this.queryParams
      }, `我审批的会议通知_${new Date().getTime()}.xlsx`)
    },
  }
};
</script>
<style lang="scss" scoped>
::v-deep .el-select,
.el-date-editor--datetime {
  width: 100%;
}
</style>
